#pragma once
#include <iostream>
#include <pthread.h>

#include "Mutex.hpp"

namespace CondMoudle
{
    using namespace MutexMoudle;
    
    class Cond 
    {
        Cond()
        {
            int n=pthread_cond_init(&_cond,nullptr);  // 表示有返回值
            (void)n;
        }
        void Wait(Mutex& mutex)
        {
            int n=pthread_cond_wait(&_cond,mutex.GetMuteOriginal());
            (void)n;
        }
        void Notify()
        {
            int n=pthread_cond_signal(&_cond);
            (void)n;
        }
        void NotifyAll()
        {
            int n=pthread_cond_broadcast(&_cond);
            (void)n;
        }
        ~Cond()
        {
            pthread_cond_destroy(&_cond);
        }


        private:
            pthread_cond_t _cond;
    };
}
